<?php
/**
 * Created by : PhpStorm
 * User: ZPF
 * Date: 2022/5/3
 * Time: 23:54
 */

namespace app\admin\controller;

use app\admin\services\SkuCategoryValueService;
use app\BaseController;
use Overtrue\Pinyin\Pinyin;
use think\facade\Validate;


class SkuCategoryValue extends BaseController
{
    protected $middleware=['CheckTokenMiddleware'=>['except'=>['index']]];
    public function index(){
        $p=$this->request->get();
        SkuCategoryValueService::tableList($p);
    }
    public function edit(){
        $p=$this->request->param();
        $p['creator_id']=$p['updater_id']=$this->request->adminUid;
        SkuCategoryValueService::edit($p);
    }
    public function del(){
        $p=$this->request->post();
        SkuCategoryValueService::del($p);
    }
    public function getPinYin(){
        $p=$this->request->post();
        $rule = [
            'name' => 'require',
        ];
        $validate=Validate::rule($rule);
        if(!$validate->check($p))
            api_return(500,$validate->getError());
        $pinyin = new Pinyin();
        // 获取中文字符串的拼音首字母缩写
        $abbreviation = $pinyin->abbr($p['name']);
        api_return(200,'',['code'=>strtoupper($abbreviation).date('ymdhis')]);

    }
}
